<template>
  <div>
    <el-drawer
      title="webhook"
      size="35%"
      :visible.sync="drawerVisible">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handlePanelAdd"
            v-hasPermi="['hawk-eye:webhook:add']"
          >新增
          </el-button>
        </el-col>
      </el-row>
      <el-row :gutter="10" class="mb8">
        <el-table
          v-loading="loading"
          :data="panelList"
        >
          <el-table-column label="名称" align="center" prop="name"/>
          <el-table-column label="请求地址" align="center" prop="webhook" :show-overflow-tooltip="true" />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                v-hasPermi="['hawk-eye:webhook:edit']"
                @click="handlePanelEdit(scope.row)"
              >编辑
              </el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                v-hasPermi="['hawk-eye:webhook:remove']"
                @click="handlePanelDelete(scope.row)"
                style="color: red;"
              >删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-row>
    </el-drawer>
    <webhook-modal-form ref="webhookModalForm" @submitted="getList"/>
  </div>
</template>

<script>

  import {
    webhookList,
    removeWebhook,
    webhookDetail
  } from "@/api/hawkeye/webhook";
  import WebhookModalForm from "@/views/hawkeye/webhook/modules/WebhookModalForm";

  export default {
    name: "WebhookDrawer",
    props: {},
    components:{
      WebhookModalForm
    },
    data() {
      return {
        title: '',
        loading: false,
        // 是否展示右键菜单
        drawerVisible: false,
        panelList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10
        },
        // 总条数
        total: 0,
      };
    },
    created() {
    },
    methods: {
      getList() {
        this.loading = true;
        webhookList(this.queryParams).then(res => {
          this.panelList = res.records;
          this.loading = false;
        });
      },
      open() {
        this.drawerVisible = true
        this.getList();
      },
      handlePanelEdit(row) {
        const id = row.id || this.ids
        webhookDetail(id).then(res => {
          this.$refs.webhookModalForm.open(res.data);
        });
      },
      handlePanelAdd() {
        this.$refs.webhookModalForm.open();
      },
      handlePanelDelete(row) {
        const ids = row.id;
        this.$modal.confirm('是否确认删除吗？').then(function () {
          return removeWebhook(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {
        });
      }
    }
  };
</script>
<style>

</style>
